<?php
require_once('MySQLdatabase.php');
 
class Student extends MySQLdatabase{
     
    public function addStudent($fname,$lname,$mi,$gender){
        $this->connectDatabase();
         
        $sQuery = "INSERT INTO student(stud_lname,stud_fname,stud_mi,stud_gender)
                    VALUES ('$fname','$lname','$mi','$gender')";
         
        $result = mysql_query($sQuery); //EXECUTE SQL
    }
     
    public function getStudent(){
        $this->connectDatabase();
        $sQuery = "SELECT stud_id,stud_lname,stud_fname,stud_mi,stud_gender FROM Student ORDER BY stud_lname ASC";
        $result = mysql_query($sQuery);
        $ctr = 0;
         
        while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
            $student[$ctr++] = array('id'=>$row['stud_id'],
                                     'lname'=>$row['stud_lname'],
                                     'fname'=>$row['stud_fname'],
                                     'mi'=>$row['stud_mi'],
                                     'gender'=>$row['stud_gender']);
        }
        
        if(!isset($student)){
            $student = null;
        }
        
        return $student;
    }
    
    public function updateStudent($id,$fname,$lname,$mi,$gender){
        $this->connectDatabase();
        $sQuery = "UPDATE Student SET stud_lname = '$lname', stud_fname = '$fname', stud_mi = '$mi', stud_gender = '$gender'
                   WHERE stud_id = $id";
        $result = mysql_query($sQuery); //EXECUTE SQL
    }
    
    public function deleteStudent($id){
        $this->connectDatabase();
        $sQuery ="DELETE FROM Student WHERE stud_id = $id";
        mysql_query($sQuery);
    }
    
    public function deleteAllStudent($id){
        $this->connectDatabase();
        $sQuery ="DELETE FROM Student";
        mysql_query($sQuery);
    }
    
    public function checkUserAccount($username,$password){
        $this->connectDatabase();
        $sQuery = "SELECT * FROM account WHERE username='$username' and userpass=md5('$password');";
        $result = mysql_query($sQuery);
        $ctr = 0;
        $row = mysql_fetch_row($result);
        if(!isset($row)){
            $row = null;
        }
        
        return $row;
    }
}


$student = new Student;
$studenAccount = $student->checkUserAccount('jrizal','1234');


if(empty($studenAccount)){
    echo "Invalid username or password";
}
else{
    print_r($studenAccount);    
}

?>